package com.ysd.dao.impl;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import com.ysd.entity.Compeny;
import com.ysd.util.DBManager;

public class CompenyDaoImpl {

	public  Compeny getCompeny() {
		Connection conn = DBManager.getConnection();
		Statement st = null;
		ResultSet rs = null;
		Compeny compeny = null;
		try {
			st = conn.createStatement();
			rs = st.executeQuery("select * from company");
			while(rs.next()) {
				int compenyId = rs.getInt("compenyId");
				String logo = rs.getString("logo");
				String url = rs.getString("url");
				String theme = rs.getString("theme");
				String introduce = rs.getString("introduce");
				String phone = rs.getString("phone");
				String email = rs.getString("email");
				String culture = rs.getString("culture");
				String adress = rs.getString("adress");
				compeny = new Compeny(compenyId, logo, url, theme, introduce, phone, email, adress, culture);
				
			}
			return compeny;
		} catch (SQLException e) {
			
			e.printStackTrace();
			return null;
		} finally {
			DBManager.closeAll(conn, st, rs);
		}
	}
	
	
	
	/**
	 * 根据公司表id修改数据
	 * @param co
	 * @return
	 */
	public int updateCompany(Compeny com) {
		String sql = "update company set logo='"+com.getLogo()+"',url='"+com.getUrl()+"',theme='"+com.getTheme()+"',introduce='"+com.getIntroduce()+"',phone='"+com.getPhone()+"',email='"+com.getEmail()+"',adress='"+com.getAdress()+"',culture='"+com.getCulture()+"'";
		System.out.println(sql);
		return DBManager.executeUpdate(sql);
	}
	
}
